package me.yuzho.study.concurrency;

import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class SimpleDaemons implements Runnable {

    @Override
    public void run() {
        
        while(true) {
            try {
                TimeUnit.MILLISECONDS.sleep(100);
                System.out.println(Thread.currentThread() + " " + this);
                
            } catch (InterruptedException e) {
                //e.printStackTrace();
                System.out.println("Sleep interrupted");
            }
        }

    }
    
    
    public static void main(String[] args) throws InterruptedException {
        IntStream.range(0, 10).forEach(i -> {
            
            Thread daemonThread = new Thread(new SimpleDaemons());
            daemonThread.setDaemon(true);
            
            daemonThread.start();
        });
        
        System.out.println("All daemons started");
        TimeUnit.MILLISECONDS.sleep(175);
    }

}
